package Control;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import Entity.*;
import GUI.ExtentionStageGui;
import GUI.ScreenManager;


public class ExtentionStage {

	private ExtentionStageGui ext_stage_gui;
	private MsgPackage mess;
	private Extention_Stage_req  extention_stage_req;
	private Object result;
	
	public ExtentionStage() {
		ext_stage_gui = new ExtentionStageGui();
		mess= new MsgPackage();
		extention_stage_req= new Extention_Stage_req();
	}

	public ExtentionStageGui getExt_stage_gui(){
		return ext_stage_gui;
	}
	
	public void reqANDstageEntered(String Req, String Stage){
		extention_stage_req.setR_id(Integer.parseInt(Req));
		extention_stage_req.setStageName(Stage);
		
	}
	
	public boolean extSubb_pressed(int id, String name){
        String x =ext_stage_gui.getTextField_numDays().getText();
		String y =ext_stage_gui.getTextField_argu().getText();
		if(x==null||y==null){
			JOptionPane.showMessageDialog(null, "Not all fileds are fill  ", "ERROR", JOptionPane.ERROR_MESSAGE);
			return false;
		}
		extention_stage_req.setR_id(id);
		extention_stage_req.setStageName(name);
		extention_stage_req.setNumDay(Integer.parseInt(ext_stage_gui.getTextField_numDays().getText()));
		extention_stage_req.setArrgumant(ext_stage_gui.getTextField_argu().getText());
		mess.setObject(extention_stage_req);
		mess.setOp_code(OP_CODE.EXTENTION_STAGE);
		ScreenManager.getConnection().accept(mess);
		
		while(ScreenManager.getConnection().getAnswerReceivedFlag() == false);	//wait until flag is changed and shows that result was received from server
    	
    	Object o = ScreenManager.getConnection().getResultobject();
    	result = (Boolean)o;
    	if((Boolean) result)
    		JOptionPane.showMessageDialog(null, "Your request has been sent for approval ", "", JOptionPane.INFORMATION_MESSAGE);    
		return true;
	}
}
